//@author A0091838U
//@The class define the Patterns of CrossOff Support 12 Time Hours Zone Format
package crossoff.datetime;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Time12HoursValidator {

	private Pattern pattern;
	private Pattern pattern1;
	private Pattern pattern2;
	private Pattern pattern3;
	private Matcher matcher;

	private static final String TIME12HOURS_PATTERN = "(1[012]|[0-9]|0[0-9]):[0-5][0-9](\\s)?(?i)(am|pm)";
	private static final String TIME12HOURS_PATTERN1 = "(1[012]|[0-9]|0[0-9])(\\s)?(?i)(am|pm)";
	private static final String TIME12HOURS_PATTERN2 = "(1[012]|0[0-9])([0-5][0-9])(\\s)?(?i)(am|pm)";
	private static final String TIME12HOURS_PATTERN3 = "(1[012]|[1-9])";

	public Time12HoursValidator() {
		pattern = Pattern.compile(TIME12HOURS_PATTERN);
		pattern1 = Pattern.compile(TIME12HOURS_PATTERN1);
		pattern2 = Pattern.compile(TIME12HOURS_PATTERN2);
		pattern3 = Pattern.compile(TIME12HOURS_PATTERN3);
	}

	/**
	 * Validate time in 12 hours format with regular expression
	 * 
	 * @param time
	 *            time address for validation
	 * @return true valid time format, false invalid time format
	 */
	public boolean validate(final String time) {
		matcher = pattern.matcher(time);
		return matcher.matches();
	}

	public boolean validate1(final String time) {
		matcher = pattern1.matcher(time);
		return matcher.matches();
	}

	public boolean validate2(final String time) {
		matcher = pattern2.matcher(time);
		return matcher.matches();
	}

	public boolean validate3(final String time) {
		matcher = pattern3.matcher(time);
		return matcher.matches();
	}

	public Pattern getPattern() {
		return pattern;
	}

	public Pattern getPattern1() {
		return pattern1;
	}

	public Pattern getPattern2() {
		return pattern2;
	}

	public Pattern getPattern3() {
		return pattern3;
	}
}